<?php

/***************************************************************\
* FILE:		/sys/gamefunctions.inc
* SECTION:	util > game functions
* FUNCTION:	reusable functions for game management
* USES:		sys/formfunctions.inc
* INCLUDES:	sys/inputcheck.inc
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

include_once('sys/inputcheck.inc');

function game_get_games() {
	$sqlresult = db_do_query(db_query_select(array(array(), "GAME.*, GAME_TYPE.*"), 
						 array("(GAME INNER JOIN GAME_OF_TYPE ON GAME.game_id = GAME_OF_TYPE.game_id) " . 
						       "INNER JOIN GAME_TYPE ON GAME_OF_TYPE.game_type_id = GAME_TYPE.game_type_id", "DUMMY"), 
						 1, "game_type ASC, name ASC"));
	$gs = array();
	while ($g = db_fetch_array($sqlresult)) {
		if (is_array($gs[$g['game_id']]) and count($gs[$g['game_id']]))
			$gs[$g['game_id']]['types'][] = $g['game_type'];
		else {
			$gs[$g['game_id']] = $g;
			$gs[$g['game_id']]['types'] = array($g['game_type']);
		}
	}
	return $gs;
}

function game_get_games_kv() {
	$sqlresult = db_do_query(db_query_select(array(array(), "GAME.*, GAME_TYPE.*"), 
						 array("(GAME INNER JOIN GAME_OF_TYPE ON GAME.game_id = GAME_OF_TYPE.game_id) " . 
						       "INNER JOIN GAME_TYPE ON GAME_OF_TYPE.game_type_id = GAME_TYPE.game_type_id", "DUMMY"), 
						 1, "game_type ASC, name ASC"));
	$keys = array();
	$values = array();
	while ($g = db_fetch_array($sqlresult)) {
		if ($prev_type != $g['game_type_id']) {
			$keys[] = "TYPE";
			$values[] = $g['game_type'];
		}
		$keys[] = $g['game_id'];
		$values[] = "&nbsp;&nbsp;&nbsp;&nbsp;{$g['name']}";
		$prev_type = $g['game_type_id'];
	}
	return array('keys' => $keys, 'values' => $values);
}

?>
